﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style>
        .content {width: 340px;height: 200px;padding: 5px;border: 1px solid #E8E5E5;border-radius: 4px;background-color: #F5F5F5;}
        .msg {border: 1px solid #EAD9A8;border-radius: 5px;background: #F7EDD2;padding: 10px;font-size: 14px;color: #D04C4C;}
        .form-control {border: 1px solid #55AD27;border-radius: 5px;height: 35px;}
        .fileinput {border-radius: 5px 0 0px 5px;cursor: pointer;padding-left:5px;width:280px;}
        .filebtn {height: 39px;margin-left: -8px;cursor: pointer;background: #359203;color: #fff;border: 1px solid #3C920E;border-left: 0px;border-radius:0px 3px 3px 0px;}
        .btn-success {display:block;padding-top:10px;height: 29px;margin-left: -8px;cursor: pointer;background: #359203;color: #fff;border: 1px solid #3C920E;border-left: 0px;border-radius:5px;width: 325px;}
    </style>
</head>
<body>
    <div class="content">
        <form id="form1" enctype='multipart/form-data' action="/admin/upload" method='post'>
            <input type="file" name="inputFile" id="inputFile" style="display:none" onchange="selectedfile()" />
            <input type="text" value="叶雨" id="name" />
            <div id="message" class="msg" style="display:none;">
                <strong style="width:250px;display:inline-block;">文件已经上传成功!</strong><a href="#" onclick="closeMsg()" style="color:#808080;cursor:pointer;">关闭</a>
            </div>
            <div style="margin-top:8px;">
                <input type="text" class="form-control fileinput" id="photoCover" placeholder="Select upload file..." onclick="selectFile()" readonly="readonly" >
                <button class="filebtn" type="button" id="browser" onclick="selectFile()">浏览</button>
            </div>
           
        </form>
         <div style="padding:8px;text-align:center;">
                <span onclick="submit()" class="btn-success">上传</span>
            </div>
    </div>
    <script type="text/javascript">
        function closeMsg() {
            document.getElementById("message").style.display="none";//隐藏  
        }
        function selectFile() {
            document.getElementById("inputFile").click();
        }
        function selectedfile() {          
            var filepath = document.getElementById("inputFile").value;
            document.getElementById("photoCover").value = filepath;
            closeMsg();
        }
        function submit() {
            var route=GetQueryString("route");
            var action=GetQueryString("action");
            var p = GetQueryString("params");
            for(i=0;i<100;i++){
                p=p.replace("|", "&");
            }
            var url="/"+route+"/"+action+"?" +p;
            alert(url);
            document.getElementById("form1").action =url;                      
            var file = document.getElementById("inputFile").value;
            if (file == "") {
                alert("请先选择文件。"); return;
            }
            else {
                var type = file.split(".")[1];               
                if (type.toLowerCase() == "jpg" || type.toLowerCase() == "png" || type.toLowerCase() == "gif"|| type.toLowerCase() == "bpm"||type=="jpeg")
                {
                    document.getElementById("form1").submit();
                }
                else {
                    alert("请选择格式为:jpg、png、gif、bpm的图片");
                }
                
            }
        }

        function GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
        
    </script>
</body>
</html>
